<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>企业招聘后台系统</title>
    <meta name="keywords" content="企业招聘后台系统">
    <meta name="description" content="企业招聘后台系统">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->

    <style>
        * {margin: 0; padding: 0; list-style: none;}
        body {width: 100%; height: 100%; background: #F5F5F5; overflow: auto; text-align: center;}
        .register-wrap {display: inline-block; margin-top: 50px; width: 600px; padding-bottom: 20px; background: #fff; text-align: center;}
        .register-wrap .title {padding-top: 20px; color: #23A7FA; font-size: 18px; font-weight: bold;}

        .register-wrap .form-wrap {padding-top: 30px;}
        .register-wrap .form-wrap .form-row {margin-bottom: 20px; position: relative;}
        .register-wrap .form-label {display: inline-block; width: 60px; text-align: right; margin-right: 6px; font-size: 14px; color: #666;}
        .register-wrap .form-input {width: 440px; height: 40px; text-indent: 12px; border: #D6D6D6; border-radius: 2px; border: 1px solid #D6D6D6;}
        .register-wrap .submit-btn {display: inline-block; width: 440px; height: 40px; line-height: 40px; color: #fff; text-align: center; border-radius: 2px; background: #23A7FA; font-size: 16px;}

        .register-wrap p.error {position: absolute; top: 41px; left: 120px; color: red; font-size: 12px;}
        .register-wrap .form-input.error {border-color: red;}
    </style>
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>
</head>

<body>
<div class="register-wrap">
    <p class="title">企业注册</p>
    <form class="form-wrap" id="registerForm">
        <div class="form-row">
            <label for="username">
                <span class="form-label">账号</span>
                <input class="form-input" type="text" name="username" id="username" onkeyup="this.value=this.value.replace(/^\s+|\s+$/g,'')" placeholder="请输入账号">
            </label>
        </div>
        <div class="form-row">
            <label for="password">
                <span class="form-label">密码</span>
                <input class="form-input" type="password" name="password" id="password" placeholder="请输入密码">
            </label>
        </div>
        <div class="form-row">
            <label for="confirmPassword">
                <span class="form-label">确认密码</span>
                <input class="form-input" type="password" name="confirmPassword" id="confirmPassword" placeholder="请输入确认密码">
            </label>
        </div>
        <div class="form-row">
            <label for="mobile">
                <span class="form-label">手机号码</span>
                <input class="form-input" type="text" name="mobile" id="mobile" placeholder="请输入手机号码">
            </label>
        </div>
        <div class="form-row">
            <label for="name">
                <span class="form-label">用户名称</span>
                <input class="form-input" type="text" name="name" id="name" placeholder="请输入公司名称">
            </label>
        </div>
        <div class="form-row">
            <label for="email">
                <span class="form-label">邮箱</span>
                <input class="form-input" type="text" name="email" id="email" placeholder="请输入邮箱">
            </label>
        </div>
        <div class="form-row">
            <label>
                <span class="form-label">&nbsp;&nbsp;</span>
                <span class="submit-btn" id="registerBtn">注&nbsp;&nbsp;册</span>
            </label>
        </div>
    </form>
</div>
<script th:inline="javascript"> var ctx = [[@{/}]] ; </script>
<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4" th:src="@{/js/jquery.min.js?v=2.1.4}"></script>
<!-- jQuery Validation plugin javascript-->
<script src="/js/ajax-util.js"></script>
<script src="/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/js/layui.js"></script>
<script src="/css/layui.css"></script>
<script>
    var $form = $('#registerForm');
    jQuery.validator.setDefaults({
        errorElement: 'p',
        //校验通过后的回调，可用来提交表单
        submitHandler: function(form, event) {
            layui.use("layer",function(){
                var layer = layui.layer;  //layer初始化
                $.ajax({
                    url : "/user/registerpc",
                    type : "post",
                    async : false,
                    data : $('#registerForm').serialize(),
                    success : function(r) {
                        if (r.code==0) {
                            parent.layer.msg("注册"+r.msg+",请使用账号密码登录！");
                            setTimeout(function(){
                                parent.location.href = '/login';
                            }, 2500);
                        } else {
                            parent.layer.msg(r.msg);
                        }
                    }
                });
            })
        },
    });
    $('#registerBtn').on('click', function () {
        $form.submit();
    });
    // 手机号码验证
    jQuery.validator.addMethod("isMobile", function (value, element) {
        var length = value.length;
        return this.optional(element) || (length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value));
    }, "请正确填写您的手机号码。");
    // 判断整数value是否大于或等于0
    jQuery.validator.addMethod("eqs", function (value, element) {
        //value = parseInt(value);
        return this.optional(element) || value == $('#password').val();
    }, "两次输入的密码不正确");
    // 判断邮箱格式
    jQuery.validator.addMethod("isEmail", function (value, element) {
        return this.optional(element) || /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.([a-zA-Z0-9_-])+)+$/.test(value);
    }, "请正确填写您的邮箱。");
    $("#registerForm").validate({
        rules: {
            username: {
                required: true
            },
            password: {
                required: true
            },
            confirmPassword: {
                required: true,
                eqs: true
            },
            mobile: {
                required: true,
                isMobile: true
            },
            name: {
                required: true,
            },
            email: {
                required: true,
                isEmail: true
            }
        },
        messages: {
            username: {required: "请输入您的账号"},
            password: {required: "请输入您的密码"},
            confirmPassword: {required: "请在次输入您的密码"},
            mobile: {required: '请输入手机号码'},
            name: {required: "请输入公司名称"},
            email: {required: "请输入您的邮箱"}
        }
    });

    $.validator.setDefaults({
        submitHandler: function () {
            login();
            // parent.location.href = '/register';
        }
    });


</script>
</body>
</html>
